package cn.ecut.ajax;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**
 * @author lujiapeng
 * @className AjaxServlet
 * @description TODO
 * @date 2020/9/16 14:50
 **/
@WebServlet("/ajax")
public class AjaxServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println( "接收到请求了");
        System.out.println( request );
        Enumeration<String> headerNames = request.getHeaderNames();
        while( headerNames.hasMoreElements() ){
            String name = headerNames.nextElement() ;
            String header = request.getHeader(name);
            System.out.println( "RequestHeaderName : " + name + " , RequestHeadValue ： " + header );
        }

        Enumeration<String> parameterNames = request.getParameterNames();
        System.out.println("getParameter");
        while( parameterNames.hasMoreElements() ){
            String name = parameterNames.nextElement() ;
            String header = request.getParameter(name);
            System.out.println( "ParameterName : " + name + " , ParameterValue ： " + header );
        }

        response.getWriter().write("我是响应");
    }
}
